
  <template>
  <div class="bf-commont-template">
    <!--<h3>动薪申请</h3>   -->
    <div class="clearfix bf-top-button">
      <div class="float-l">
        <!--<bf-form-user :form="formUser" :item="formItem"></bf-form-user>-->
        <el-button type="primary" style="margin-left: 10px" @click="showYear">申请年度调薪</el-button>
      </div>
      <div class="float-r">
        <div class="float-l">
          <el-input placeholder="请输入员工名称搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch"></el-input>
        </div>
        <div class="float-l padding-l">
          <el-button @click="showSearch" type="primary">高级筛选</el-button>
        </div>
      </div>
    </div>
    <div class="margin-l margin-r">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane :label="'入职动薪申请'+ tabs.countEntry" countEntry status="0" name="countEntry">
          <bf-table :data="userData" :setting="delayListSetting" :rowAction="delayRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'转正动薪申请' + tabs.countConrrection" status="1" name="countConrrection">
          <bf-table :data="userData" :setting="conrrectionListSetting" :rowAction="conrrectionRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'调动动薪申请' + tabs.countTurnover" status="2" name="countTurnover">
          <bf-table :data="userData" :setting="turnoverListSetting" :rowAction="turnoverRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'年度动薪申请' + tabs.countYear" status="3" name="countYear">
          <bf-table :data="userData" :setting="leaveListSetting" :rowAction="leaveRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="yearTable"></bf-table>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!--高级搜索 -->
    <bf-table-search :editForm='searchSetting' :title="'高级搜索'" ref='searchRosterRef' @formSubmit='searchRosterSubmit'></bf-table-search>
    <!-- 添加 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='addYearSetting' :title="'添加年度调薪'" ref='addYearRef' :submitButtons="addYearButtons" :editRules="addYearRules" @formSubmit='addYearSubmit'></bf-table-edit>

    <!-- 入职审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='delayApproveSetting' :title="'入职审批'" :submitButtons="delayApproveSubmitButtons" ref='delayApproveRef' :editRules="addRules"></bf-table-edit>
    <!--入职详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="delayDetailRef" :title="'入职详情'" :editForm="delayDetailSetting" :showHistory='true' :approveSetting='entrySettingHis'></bf-table-detail>
    <bf-table-edit :width="800" :rowNum="2" :editForm='delayApproveSetting' :title="'入职审批'" :submitButtons="entryBackSubmitButtons" ref='entryBackApproveRef' :editRules="addRules"></bf-table-edit>

    <!-- 转正详情 -->
    <bf-table-detail :width="800" :rowNum="2" ref="conrrectionDetailRef" :title="'转正详情'" :editForm="conrrectionDetailSetting" :showHistory='true' :approveSetting='conrrectionSettingHis'></bf-table-detail>
    <!-- 转正审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='conrrectionApproveSetting' :title="'转正审批'" :submitButtons="conrrectionApproveSubmitButtons" ref='conrrectionApproveRef' :editRules="addRules"></bf-table-edit>
    <bf-table-edit :width="800" :rowNum="2" :editForm='conrrectionApproveSetting' :title="'转正审批'" :submitButtons="conrrectionBackSubmitButtons" ref='conrrectionBackApproveRef' :editRules="addRules"></bf-table-edit>

    <!--调动详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="turnoverDetailRef" :title="'调动详情'" :editForm="turnoverApproveSetting" :showHistory='true' :approveSetting='turnoverSettingHis'></bf-table-detail>
    <!-- 调动审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='turnoverApproveSetting' :title="'调动审批'" :submitButtons="turnoverApproveSubmitButtons" ref='turnoverApproveRef' :editRules="addRules"></bf-table-edit>
    <bf-table-edit :width="800" :rowNum="2" :editForm='turnoverApproveSetting' :title="'调动审批'" :submitButtons="turnoverBackSubmitButtons" ref='turnoverBackApproveRef' :editRules="addRules"></bf-table-edit>
    <!--年度详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="leaveDetailRef" :title="'年度详情'" :editForm="yeardetailSetting" :showHistory='true' :approveSetting='yearSettingHis'></bf-table-detail>
    <!-- 年度审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='leaveApproveSetting' :title="'年度调薪审批'" :submitButtons="leaveApproveSubmitButtons" ref='leaveApproveRef' :editRules="addYearRules"></bf-table-edit>

    <bf-table-edit :width="800" :rowNum="2" :editForm='editYearApproveSetting' :title="'年度调薪审批'" :submitButtons="leaveApproveSubmitButtons" ref='yearApproveRef' :editRules="addYearRules"></bf-table-edit>
  </div>
</template>

<script>
import {
  updateNd, deleteNd,
  insertNd, findStatusCount, getDealDelayList,
  getConrrectionList, getTurnoverList,
  getLeaveList, findDelayDetail, findConrrectDetail, findTurnoverDetail,
  findLeaveDetail, dealDelayApprove, dealConrrectionApprove,
  dealTurnoverApprove, dealLeaveApprove, updateBackNd, updateBackConrrectionSalary,
  updateBackTurnoverSalary, updateBackEntrySalary
} from './api.js'
import { searchSetting, addYearSetting, delayListSetting, delayDetailSetting, delayApproveSetting, conrrectionListSetting, conrrectionDetailSetting, conrrectionApproveSetting, turnoverListSetting, turnoverDetailSetting, turnoverApproveSetting, leaveListSetting, leaveDetailSetting, leaveApproveSetting, yeardetailSetting, editYearApproveSetting } from './table.setting.js'
export default {

  data() {
    return {
      entrySettingHis: {
        procDefKey: 'employee-entry',
        businessKey: ''
      },
      conrrectionSettingHis: {
        procDefKey: 'employee-conrrection',
        businessKey: ''
      },
      turnoverSettingHis: {
        procDefKey: 'employee-turnover',
        businessKey: ''
      },
      yearSettingHis: {
        procDefKey: 'employee-year',
        businessKey: ''
      },
      formUser: {},
      formItem:
      {
        field: 'userId',
        type: 'user'
      },
      searchData: '',
      activeName: 'countEntry',
      statusData: {},
      addYearButtons: [
        {
          title: '提交',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)

            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.status = 1
              form.action = 1
              this.addYearSubmit(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        // {
        //   title: '保存',
        //   click: (form) => {
        //     const targetSalary = Number(form.targetSalary)
        //     const salaryLow = Number(form.salaryLow)
        //     const salaryHigh = Number(form.salaryHigh)
        //     if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
        //       form.status = 0
        //       form.action = 1
        //       this.addYearSubmit(form)
        //     } else {
        //       this.$message({
        //         message: '总薪资不在岗位薪资内！',
        //         type: 'error'
        //       })
        //       return false
        //     }
        //   }
        // },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.addYearRef.hiden()
          }
        }
      ],
      delayApproveSubmitButtons: [
        {
          title: '同意',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.action = 1
              form.status = 1
              this.delayApprove(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = '0'
            form.status = 1
            // console.log(form)

            this.delayApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.delayApproveRef.hiden()
          }
        }
      ],

      entryBackSubmitButtons: [
        {
          title: '提交',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.status = 1
              form.action = 1
              this.backEntrySalary(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '保存',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.status = 0
              form.action = 1
              this.backEntrySalary(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.delayApproveRef.hiden()
          }
        }
      ],

      conrrectionApproveSubmitButtons: [
        {
          title: '同意',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.action = 1
              form.status = 1
              this.conrrectionApprove(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = 0
            form.status = 1
            // console.log(form)

            this.conrrectionApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.conrrectionApproveRef.hiden()
          }
        }
      ],
      conrrectionBackSubmitButtons: [
        {
          title: '提交',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.action = 1
              form.status = 1
              this.backConrrectionSalary(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }




            // this.delayApprove(form)
          }
        },
        {
          title: '保存',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.action = 1
              form.status = 0
              this.backConrrectionSalary(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }


            // this.delayApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.delayApproveRef.hiden()
          }
        }
      ],

      turnoverApproveSubmitButtons: [
        {
          title: '同意',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.action = 1
              form.status = 1
              this.turnoverApprove(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = 0
            form.status = 1
            // console.log(form)

            this.turnoverApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.turnoverApproveRef.hiden()
          }
        }
      ],
      turnoverBackSubmitButtons: [
        {
          title: '提交',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.action = 1
              form.status = 1
              this.backTurnoverSalary(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '保存',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              form.action = 1
              form.status = 0
              this.backTurnoverSalary(form)
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.delayApproveRef.hiden()
          }
        }
      ],
      leaveApproveSubmitButtons: [
        {
          title: '提交',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              if (form.status === '1') {
                form.status = 1
                form.action = 1
                this.leaveApprove(form)
              } else {
                this.updateyear(form)
              }
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '保存',
          click: (form) => {
            const targetSalary = Number(form.targetSalary)
            const salaryLow = Number(form.salaryLow)
            const salaryHigh = Number(form.salaryHigh)
            if (salaryLow <= targetSalary && targetSalary <= salaryHigh) {
              if (form.status === '1') {
                form.status = 0
                form.action = 1
                // console.log(form)
                this.leaveApprove(form)
              } else {
                form.status = 0
                form.action = 1
                this.updateyear(form)
              }
            } else {
              this.$message({
                message: '总薪资不在岗位薪资内！',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.yearApproveRef.hiden()
            this.$refs.leaveApproveRef.hiden()
          }
        }
      ],
      tabs: {
        countEntry: 0,
        countConrrection: 0,
        countTurnover: 0,
        countYear: 0,
      },
      userData: {
      },

      delayRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.entrySettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.delayDetailRef.show)
          }
        },
        {
          label: '填写申请',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'writeSalary') {
              return true
            } else if (row.taskDefKey === 'modifySalary') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'writeSalary') {
              this.findDetailById(item.scope.row.id, this.$refs.delayApproveRef.show)
            } else if (item.scope.row.taskDefKey === 'modifySalary') {
              this.findDetailById(item.scope.row.id, this.$refs.entryBackApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          label: '退回',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'writeSalary') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'writeSalary') {
              item.scope.row.action = 0
              this.delayApprove(item.scope.row)
            } else {
              this.$message({
                message: '该阶段不可退回',
                type: 'error'
              })
              return false
            }
            // this.findDetailById(item.scope.row.id, this.$refs.delayApproveRef.show)
          }
        }
      ],
      conrrectionRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.conrrectionSettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.conrrectionDetailRef.show)
          }
        },
        {
          label: '填写申请',
          click: (item) => {
            if (item.scope.row.taskDefKey === 'writeSalary') {
              this.findDetailById(item.scope.row.id, this.$refs.conrrectionApproveRef.show)
            } else if (item.scope.row.taskDefKey === 'modifySalary') {
              this.findDetailById(item.scope.row.id, this.$refs.conrrectionBackApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          label: '退回',
          click: (item) => {
            if (item.scope.row.taskDefKey === 'writeSalary') {
              item.scope.row.action = 0
              this.conrrectionApprove(item.scope.row)
            } else {
              this.$message({
                message: '该阶段不可退回',
                type: 'error'
              })
              return false
            }
            // this.findDetailById(item.scope.row.id, this.$refs.delayApproveRef.show)
          }
        }, {
          label: '放弃申请',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'modify') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'modify') {
              item.scope.row.action = 0
              item.scope.row.action = 0
              this.conrrectionApprove(item.scope.row)
            } else {
              this.$message({
                message: '该阶段不放弃',
                type: 'error'
              })
              return false
            }
          }
        }


      ],
      turnoverRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.turnoverSettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.turnoverDetailRef.show)
          }
        },
        {
          label: '填写申请',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'writeSalary') {
              return true
            } else if (row.taskDefKey === 'modifySalary') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'writeSalary') {
              this.findDetailById(item.scope.row.id, this.$refs.turnoverApproveRef.show)
            } else if (item.scope.row.taskDefKey === 'modifySalary') {
              this.findDetailById(item.scope.row.id, this.$refs.turnoverBackApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          label: '退回',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'writeSalary') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'writeSalary') {
              item.scope.row.action = 0
              this.turnoverApprove(item.scope.row)
            } else {
              this.$message({
                message: '该阶段不可退回',
                type: 'error'
              })
              return false
            }
            // this.findDetailById(item.scope.row.id, this.$refs.delayApproveRef.show)
          }
        }, {
          label: '放弃申请',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'modify') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'modify') {
              item.scope.row.action = 0
              item.scope.row.action = 0
              this.turnoverApprove(item.scope.row)
            } else {
              this.$message({
                message: '该阶段不放弃',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      leaveRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.yearSettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.leaveDetailRef.show)
          }
        },
        {
          label: '编辑',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'modify') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'modify' || item.scope.row.taskDefKey === undefined) {
                this.findDetailById(item.scope.row.id, this.$refs.yearApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          label: '提交',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'modify') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'modify') {
              this.yearSubmint(item.scope.row.id)
            } else if (item.scope.row.taskDefKey === undefined) {
                item.scope.row.action = 1
                item.scope.row.status = '1'
                this.updateyear(item.scope.row)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          label: '删除',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'modify') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.status === '0') {
              this.$refs.yearTable.showDelete(item)
            } else {
              this.$message({
                message: '退回修改状态不可删除',
                type: 'error'
              })
              return false
            }
          }
        },
        {
          label: '放弃申请',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'modify') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'modify') {
              item.scope.row.action = 0
              item.scope.row.action = 0
              this.leaveApprove(item.scope.row)
            } else {
              this.$message({
                message: '该阶段不放弃',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      searchSetting: searchSetting,
      addYearSetting: addYearSetting,
      delayListSetting: delayListSetting, // 入职列表
      delayDetailSetting: delayDetailSetting,
      delayApproveSetting: delayApproveSetting,
      conrrectionListSetting: conrrectionListSetting, // 转正
      conrrectionDetailSetting: conrrectionDetailSetting,
      conrrectionApproveSetting: conrrectionApproveSetting,

      turnoverListSetting: turnoverListSetting, // 调离
      turnoverDetailSetting: turnoverDetailSetting,
      turnoverApproveSetting: turnoverApproveSetting,
      leaveListSetting: leaveListSetting, // 年度
      leaveDetailSetting: leaveDetailSetting,
      leaveApproveSetting: leaveApproveSetting,
      yeardetailSetting: yeardetailSetting,
      editYearApproveSetting: editYearApproveSetting,

      addRules: {
        reqName: [
          { required: true, message: '请输入需求名称', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50个字符', trigger: 'blur' }
        ],
        approvalOpinion: [
          { required: true, message: '审批意见必填', trigger: 'blur' }
        ],
        effectDate: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      },
      stopRules: {
        stopReason: [
          { required: true, message: '请输入停止招聘原因', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50个字符', trigger: 'blur' }
        ],
        effectDate: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      },
      addYearRules: {
        targetPostLevel: [
          { required: true, message: '请输入需求名称', trigger: 'blur' }
        ],
        targetLevel: [
          { required: true, message: '请选择职级', trigger: 'blur' }
        ],
        effectDate: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        employeeNo: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]

      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList('')
  },
  methods: {
    showYear() {
      const obj = {
        targetSalary: 0,
        targetBaseSalary: 0,
        targetPostSalary: 0,
        targetAllowance: 0,
        targetAchievementBonus: 0,
        targetOtherReward: 0,
        targetFullattendReward: 0,
        targetLevelSalary: 0,
        targetPostLevel: '',
        entryDate: 0,
        orgId: 0,
        position: 0,
        postLevel: 0,
        targetLevel: '',
        salaryLow: 0,
        salaryHigh: 0,
        baseSalary: 0,
        postLevelSalary: 0,
        postAllowance: 0,
        achievementBonus: 0,
        fullAttendenceReward: 0,
        otherReward: 0,
        salary: 0
      }

      this.$refs.addYearRef.show(obj)
    },

    updateyear(form) {
      updateNd(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.leaveApproveRef.hiden()
          this.$refs.yearApproveRef.hiden()
          this.searchList()
        }
      })
    },
    addYearSubmit(form) { // 新增年度调薪
      insertNd(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.addYearRef.hiden()
          this.searchList()
        }
      })
    },

    searchRosterSubmit(form) { // 高级搜索
      this.searchParams.page = 1
      this.searchParams.employeeName = form.employeeName
      this.searchParams.employeeNo = form.employeeNo
      this.searchParams.entryDate = form.entryDate
      this.searchParams.status = form.status
      this.searchParams.orgId = form.targetOrgId
      this.searchParams.post = form.post
      this.searchParams.postLevel = form.postLevel
      this.searchList()
      this.$refs.searchRosterRef.hiden()
    },


    yearSubmint(Id) { // 列表提交年度调薪
      const params = {
        id: Id
      }

      findLeaveDetail(params).then((response) => {
        if (response.data.status === '0') {
          response.data.status = 1
          response.data.action = 1
          // 缺乏第一次编辑提交
          insertNd(response.data).then((response) => {
            if (response.success) {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.$refs.addYearRef.hiden()
              this.searchList()
            }
          })
        } else {
          response.data.action = 1
          updateBackNd(response.data).then((response) => {
            if (response.success) {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.$refs.leaveApproveRef.hiden()
              this.$refs.yearApproveRef.hiden()
              this.searchList()
            }
          })
        }
      })
    },

    delayApprove(form) { // 延期同意不同意
      dealDelayApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.delayApproveRef.hiden()
          this.$refs.entryBackApproveRef.hiden()
          this.searchList()
        }
      })
    },
    conrrectionApprove(form) { // 转正
      dealConrrectionApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.conrrectionApproveRef.hiden()
          this.$refs.conrrectionBackApproveRef.hiden()
          this.searchList()
        }
      })
    },
    turnoverApprove(form) { // 调离
      dealTurnoverApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.turnoverApproveRef.hiden()
          this.$refs.turnoverBackApproveRef.hiden()
          this.searchList()
        }
      })
    },

    leaveApprove(form) { // 年度
      dealLeaveApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.leaveApproveRef.hiden()
          this.$refs.yearApproveRef.hiden()

          this.searchList()
        }
      })
    },


    getTabs(status) {
      findStatusCount(status).then((request) => {
        this.statusData = request.data
        this.tabs.countEntry = request.data[0].countEntry
        this.tabs.countDelay = request.data[0].countDelay
        this.tabs.countConrrection = request.data[0].countConrrection
        this.tabs.countTurnover = request.data[0].countTurnover
        this.tabs.countLeave = request.data[0].countLeave
        this.tabs.countYear = request.data[0].countYear
      })
    },

    // updateBackConrrectionSalary,updateBackTurnoverSalary,updateBackEntrySalary

    backConrrectionSalary(form) {
      // 退回后修改转正动薪
      updateBackConrrectionSalary(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.conrrectionApproveRef.hiden()
          this.$refs.conrrectionBackApproveRef.hiden()
          this.searchList()
        }
      })
    },
    backTurnoverSalary(form) {
      // 退回后修改调岗动薪
      updateBackTurnoverSalary(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.turnoverApproveRef.hiden()
          this.$refs.turnoverBackApproveRef.hiden()

          this.searchList()
        }
      })
    },
    backEntrySalary(form) {
      // 退回后修改入职动薪
      updateBackEntrySalary(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.delayApproveRef.hiden()
          this.$refs.entryBackApproveRef.hiden()

          this.searchList()
        }
      })
    },

    findDetailById(Id, showCall) { // 详情
      const status = this.getActivityStatus()
      const params = {
        id: Id
      }

      if (status === 0) {
        findDelayDetail(params).then((response) => { // 入职
          showCall(response.data)
        })
      }
      if (status === 1) {
        findConrrectDetail(params).then((response) => { // 转正
          showCall(response.data)
        })
      }
      if (status === 2) {
        findTurnoverDetail(params).then((response) => { // 调动
          showCall(response.data)
        })
      }
      if (status === 3) {
        findLeaveDetail(params).then((response) => { // 年度
          showCall(response.data)
        })
      }
    },


    searchList() {
      const pageParams = this.searchParams
      const status = this.getActivityStatus()
      // if (!pageParams.status) {
      //   pageParams.status = '1'
      // }
      this.getTabs(pageParams.status)
      if (status === 0) {
        getDealDelayList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 1) {
        getConrrectionList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 2) {
        getTurnoverList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 3) {
        getLeaveList(pageParams).then((response) => {
          this.userData = response
        })
      }
    },

    editSubmit(params, formType, formList) {
      // console.log(params, formType, formList)

      deleteNd(params.row).then((response) => {
        if (response.success) {
          this.$message({
            message: '删除成功!',
            type: 'success'
          })
          this.searchList()
        }
      })
    },
    pageChange(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
      // this.searchList(pageObj)
    },
    showSearch() {
      if (this.activeName == 'countYear') {
        this.searchSetting.some(v => {
          if (v.field == "status") {
            v.options = [
              {
                name: '审批中',
                value: '1'
              },
              {
                name: '退回待修改',
                value: '3'
              },
              {
                name: '审批通过',
                value: '2'
              }
            ]
            return true
          }
        })
      } else {
        this.searchSetting.some(v => {
          if (v.field == "status") {
            v.options = [
              {
                name: '填写动薪',
                value: '1'
              },
              {
                name: '审批通过',
                value: '2'
              },
              {
                name: '已放弃',
                value: '9'
              }
            ]
            return true
          }
        })
      }

      this.$refs.searchRosterRef.show()
    },
    addreq() {
      this.$refs.addRosterRef.show()
    },
    quickSearch() {
      this.searchParams.page = 1
      this.searchParams.employeeName = this.searchData
      this.searchList()
    },
    handleClick(tab, event) {
      this.searchList()
    },
    addPlan() {

    },

    getActivityStatus() {
      if (this.activeName === 'countEntry') {
        return 0;
      }
      if (this.activeName === 'countConrrection') {
        return 1;
      }
      if (this.activeName === 'countTurnover') {
        return 2;
      }
      if (this.activeName === 'countYear') {
        return 3;
      }
    }
  }
}
</script>

<style scoped>

</style>
